<template>
  <a-row style="padding: 0 0 25px 0">
    <a-col :span="4">
      <a-select v-model:value="whole" style="width: 120px" @change="handleChange">
        <a-select-option v-for="sj in eastWestData" :value="sj._id">
          {{ sj.name }}
        </a-select-option>

      </a-select>
    </a-col>
    <a-col :span="1">

    </a-col>
    <a-col :span="5">
      <a-input v-model:value="Obgconstraint.author" placeholder="请输入作者名" />
    </a-col>
    <a-col :span="2">

    </a-col>
    <a-col :span="6">
      <a-input v-model:value="Obgconstraint.title" placeholder="请输入标题" />
    </a-col>
    <a-col :span="2">

    </a-col>
    <a-col :span="4">
      <a-button @click="search">搜索</a-button>
    </a-col>
  </a-row>

  <a-button type="primary" @click="release">
    发布
  </a-button>
  <a-modal v-model:visible="visible" :title="TitleChanges" @ok="successcg">

    <a-form :model="Obgconstraint" name="basic" :label-col="{ span: 4 }" :wrapper-col="{ span: 16 }" autocomplete="off">
      <a-form-item label="标题" name="title">
        <a-input v-model:value="ObjectConstraints.title" placeholder="请输入标题" />
      </a-form-item>

      <a-form-item label="内容" name="content">
        <a-textarea v-model:value="ObjectConstraints.content" show-count :maxlength="200" placeholder="请输入发布内容" />

      </a-form-item>

      <a-form-item label="分类" name="cate_name">
        <a-select v-model:value="ObjectConstraints.cate_id" style="width: 120px" @change="handleChange">
          <a-select-option @click="obtain(sj.name)" v-for="sj in eastWestData" :value="sj._id">
            {{ sj.name }}
          </a-select-option>

        </a-select>
      </a-form-item>


      <pictures ref="Exposurer">

      </pictures>






    </a-form>


  </a-modal>
  <a-table :columns="columns" :data-source="list" :pagination="false">
    <template #headerCell="{ column }">
      <template v-if="column.key === 'name'">
        <span>
          <smile-outlined />
          标题
        </span>
      </template>
    </template>

    <template #bodyCell="{ column, record }">
      <template v-if="column.key === 'name'">
        <a>
          {{ record.name }}
        </a>
      </template>

      <template v-else-if="column.key === 'action'">
        <span>

          <a>删除</a>
          <span>|</span>
          <a @click="change(record)">
            更改

          </a>
        </span>
      </template>
    </template>
  </a-table>
  <a-pagination v-model:current="paging.current" :total="paging.total" @change="ChangePagination" />
</template>
<script lang="ts" setup>
import { columns, Obgconstraint, whole, handleChange, search, paging, ChangePagination, gzhs, methodslist, list } from './artivelist'
import { getarticleAllnewly } from '@/api/Artive/ArticleAll'
import type { TDefinition } from '@/types/artive/artivelist'
import { ref, reactive } from 'vue'
import pictures from '@/components/uploadPictures/list.vue'
import { usestore } from '@/stores/index'
import { message } from 'ant-design-vue'
import type { string } from '_vue-types@3.0.2@vue-types'
const sj = usestore()

let { eastWestData } = gzhs()

let Exposurer = ref<any>(null)
const ObjectConstraints: TDefinition = reactive({
  article_id: '',
  title: '',
  content: '',
  cate_name: '',
  cate_id: '',
  imageSrc: [],
  author: '',
  author_id: '',
  type: '1'
})
const visible = ref<boolean>(false);
let TitleChanges = ref<string>('发布')
const showModal = () => {
  visible.value = true;
};
function obtain(e: string) {
  console.log(e)
  ObjectConstraints.cate_name = e
}
function successcg(e: any) {
  if (ObjectConstraints.type == '1') {
    Reflect.deleteProperty(ObjectConstraints, 'article_id')
    console.log(ObjectConstraints)
  } else {
    // let _idd=list.value.map((v:any)=>{
    //       return v._id
    //     })
    //     console.log(_idd)
    // ObjectConstraints.article_id=list.value/
    console.log(ObjectConstraints)

  }
  console.log(e)
  console.log(ObjectConstraints)
  let imgsrc = Exposurer.value.fileList.map((v: any) => {
    return 'http://toutiao.longxiaokj.com/' + v.response.key
  })
  ObjectConstraints.author = sj.userInfo.nickname
  ObjectConstraints.author_id = sj.uid
  ObjectConstraints.imageSrc = imgsrc || []
  console.log(Exposurer.value.fileList)
  console.log(ObjectConstraints)
  getarticleAllnewly(ObjectConstraints).then((res: any) => {
    console.log(res)
    if (res.code == 0) {
      message.success(res.msg)
      console.log(ObjectConstraints)
      visible.value = false
      methodslist()
    } else {
      message.warning(res.msg)
      // showModal()
      // methodslist()


    }
  })
}
function release() {
  eastWestData.value.splice(0,1)
  TitleChanges.value = '发布'
  ObjectConstraints.type = '1'
  console.log(ObjectConstraints)
  showModal()
  console.log('13123')
  console.log(eastWestData.value[0])
  //  let sj=eastWestData.value.splice(0,1)
  console.log(eastWestData.value)

}

function change(e: any) {
  eastWestData.value.splice(0,1)
  console.log(eastWestData.value)
  showModal()
  ObjectConstraints.type = '0'
  TitleChanges.value = '更改'
  // let _idd=list.value.map((v:any)=>{
  //       return  ObjectConstraints.article_id=v._id
  //     })
  //     console.log(_idd)
  console.log(e._id)
  ObjectConstraints.article_id = e._id
  console.log(ObjectConstraints.article_id)

}
</script>
  
  